package email

import "gopkg.in/gomail.v2"

func SendMail(from,password string,to,cc,attach []string,msg,subject string)error {
	var (
		toValue []string
		ccValue []string
	)

	m := gomail.NewMessage()

	for _, v := range to{
		toValue = append(toValue,m.FormatAddress(v,"收件人"))
	}

	for _, v := range cc{
		ccValue = append(ccValue,m.FormatAddress(v,"收件人"))
	}

	m.SetAddressHeader("From",from,"发件人")
	m.SetHeader("To",toValue...)
	m.SetHeader("Cc",ccValue...)

	m.SetHeader("Subject",subject)
	m.SetBody("text/plain",msg)
	for _, v := range attach{
		m.Attach(v)
	}

	d := gomail.NewDialer("smtp.163.com",25,from,password)
	return d.DialAndSend(m)
}
